package com.example.crazyfall;

import org.andengine.engine.Engine;
import org.andengine.engine.camera.Camera;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color;
import org.andengine.util.debug.Debug;



public class ResorucesManager {
	
	
	    // VARIABLES de los engine
	    
	    private static final ResorucesManager INSTANCE = new ResorucesManager();
	    
	    public Engine engine;
	    public MainActivity activity;
	    public Camera camera;
	    public VertexBufferObjectManager vbom;
	   
	    // Variables de la escena splash
	    public ITextureRegion splashReg;
	    private BitmapTextureAtlas splashText;
	    
	    //Variables de la escena de Menu
	    public ITextureRegion fondoMenu;
	    public ITextureRegion juegoRegion;
	    public ITextureRegion opcionRegion;
	    public ITextureRegion ayudaRegion;
	    private BuildableBitmapTextureAtlas menuTextureAtlas;
	    
	    //Variables de la escena de la escena Configuracion
	    public ITextureRegion fondoConfiguracion;
	    public ITextureRegion regresoConfigRegion;
	    private BuildableBitmapTextureAtlas configTextureAtlas;

	    //Variables de la escena de la escena ayuda
	    public ITextureRegion fondoAyuda;
	    public ITextureRegion regresoAyudaRegion;
	    private BuildableBitmapTextureAtlas ayudaTextureAtlas;

	    //Metodo para cargar los recursos del menu
	    public void loadMenuResources()
	    {
	        loadMenuGraphics();
	    }
	    
	    //Metodo para cargar los recursos de la configuracion
	    public void loadConfigurationResources()
	    {
	        loadConfigurationGraphics();
	    }
	    
	    //Metodo para cargar los recursos de la pantalla ayuda
	    public void loadHelpResources()
	    {
	        loadHelpGraphics();
	    }
	    
	    //Metodo para cargar los recursos del la escena del juego
	    public void loadGameResources()
	    {
	        loadGameGraphics();
	        loadGameFonts();
	    }
	        
	    //Metodo para cargar los recursos la parte grafica de la pantalla de configuracion
	    private void loadConfigurationGraphics()
	    {
	    	BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("menu/");
	    	configTextureAtlas = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
	    	fondoConfiguracion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(configTextureAtlas, activity, "instrucciones_fondo.jpg");
	    	regresoConfigRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(configTextureAtlas, activity, "regresar1.png");
	    	       
	    	try 
	    	{
	    	    this.configTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	    	    this.configTextureAtlas.load();
	    	} 
	    	catch (final TextureAtlasBuilderException e)
	    	{
	    	        Debug.e(e);
	    	}
	        
	    }

	    //Metodo para cargar los recursos la parte grafica de la pantalla de ayuda
	    private void loadHelpGraphics()
	    {
	    	BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("menu/");
	    	ayudaTextureAtlas = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
	    	fondoAyuda = BitmapTextureAtlasTextureRegionFactory.createFromAsset(ayudaTextureAtlas, activity, "ajustes.jpg");
	    	regresoAyudaRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(ayudaTextureAtlas, activity, "regresar1.png");
	    	            
	    	try 
	    	{
	    	    this.ayudaTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	    	    this.ayudaTextureAtlas.load();
	    	} 
	    	catch (final TextureAtlasBuilderException e)
	    	{
	    	        Debug.e(e);
	    	}
	        
	    }
	    
	    //Metodo para cargar los recursos la parte grafica de la pantalla de menu
	    private void loadMenuGraphics()
	    {
	    	BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("menu/");
	    	menuTextureAtlas = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
	    	fondoMenu = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTextureAtlas, activity, "menu_inicio_avioneta.jpg");
	    	juegoRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTextureAtlas, activity, "play.1.png");
	    	ayudaRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTextureAtlas, activity, "help1.png");
	    	opcionRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTextureAtlas, activity, "ajustes1.png");
	    	       
	    	try 
	    	{
	    	    this.menuTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	    	    this.menuTextureAtlas.load();
	    	} 
	    	catch (final TextureAtlasBuilderException e)
	    	{
	    	        Debug.e(e);
	    	}
	        
	    }
	    
	    //Metodo para cargar los recursos la parte grafica de la pantalla del juego
	    private void loadGameGraphics()
	    {
	        
	    }
	    
	    //Metodo para cargar los recursos la parte grafica de la pantalla de configuracion
	    private void loadGameFonts()
	    {
	        
	    }
	    
	    //Metodo para cargar escena de splash
	    public void loadSplashScreen()
	    {
	    	BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("menu/");
	    	splashText = new BitmapTextureAtlas(activity.getTextureManager(), 400, 850, TextureOptions.BILINEAR);
	    	splashReg = BitmapTextureAtlasTextureRegionFactory.createFromAsset(splashText, activity, "logoEspera.png", 0, 0);
	    	splashText.load();
	    }
	    
	    //Metodo para dar de baja escena de splash
	    public void unloadSplashScreen()
	    {
	    	splashText.unload();
	    	splashReg = null;	    	
	    }
	    
	    //Metodo para preparar el engine
	    public static void prepareManager(Engine engine, MainActivity activity, Camera camera, VertexBufferObjectManager vbom)
	    {
	        getInstance().engine = engine;
	        getInstance().activity = activity;
	        getInstance().camera = camera;
	        getInstance().vbom = vbom;
	    }
	    
	    //Metodo para obtener la instancia
	    public static ResorucesManager getInstance()
	    {
	        return INSTANCE;
	    }
	
	    //Metodo para descargar escena de menu
	    public void unloadMenuTextures()
	    {
	        menuTextureAtlas.unload();
	    }
	        
	    //Metodo para cargar escena de menu
	    public void loadMenuTextures()
	    {
	        menuTextureAtlas.load();
	    }
	    
	    //Metodo para descargar escena de configuracion
	    public void unloadConfigTextures()
	    {
	    	configTextureAtlas.unload();
	    }
	       
	    //Metodo para cargar escena de configuracion
	    public void loadConfigTextures()
	    {
	    	configTextureAtlas.load();
	    }
	    
	    //Metodo para descargar escena de ayuda
	    public void unloadHelpTextures()
	    {
	    	ayudaTextureAtlas.unload();
	    }
	       
	    //Metodo para cargar escena de ayuda
	    public void loadHelpTextures()
	    {
	    	ayudaTextureAtlas.load();
	    }
	  
	    //Variable para el font
	    public Font font;

	    

}
